<template>
    <cover-view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
        <cover-view class="tabbar-item" v-for="(item, index) in list"  :key="index"  @click="tabbarChange(item.path,index)">
            <cover-image class="item-img" :src="item.icon_selected" v-if="selected == index"></cover-image>
            <cover-image class="item-img" :src="item.icon" v-else></cover-image>
            <cover-view class="item-name" :class="{'tabbarActive': selected == index}" v-if="item.text">{{item.text}}</cover-view>
        </cover-view>
    </cover-view>
</template>

<script>
export default {
    props: {
        selected:{
			type:Number, 
			default: 0,
		},
    },
    data() {
        return {
            list: [{
                    text: '首页',  
                    icon: '/static/image/tabbar/index_icon.png',  //未选中图标
                    icon_selected: '/static/image/tabbar/index_icon_selected.png',  //选中图片
                    path: "/pages/index/index",  //页面路径
                },{
                    text: '任务',
                    icon: '/static/image/tabbar/mask_icon.png',
                    icon_selected: '/static/image/tabbar/mask_icon_selected.png',
                    path: "/pages/mask/index/index",
                }
                ,{
                    text: '发起',
                    icon: '/static/image/tabbar/launch_icon.png',
                    icon_selected: '/static/image/tabbar/launch_icon_selected.png',
                    path: '/pages/initiate/index/index',
                },{
                    text: '我的',
                    icon: '/static/image/tabbar/my_icon.png',
                    icon_selected: '/static/image/tabbar/my_icon_selected.png',
                    path: "user",
                },
            ]
        };
    },
    methods: {
        tabbarChange(path,index) {
			let that = this;
			that.$emit('click', path);
			uni.reLaunch({
				url:path
			});
			
        }
    }
};
</script>

<style lang="scss" scoped>
    .tabbarActive{
            color: #79D5AD !important;
        }
        .tabbar{
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            display: flex;
            justify-content: space-around;
            align-items: center;
            width: 100%;
            height: 100rpx;
                    background-color: #ffffff;
            .tabbar-item{
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                height: 100rpx;
                .item-img{
                    margin-bottom: 4rpx;
                    width: 46rpx;
                    height: 46rpx;
                }
                .item-name{
                    font-size: 26rpx;
                    color: #A3A3A3;
                }
            }
        }
</style>